import { Component, ElementRef, OnInit, Output, Input, ViewChild, AfterViewInit, EventEmitter } from '@angular/core';
import { HttpModule, Headers, RequestOptions, Http } from '@angular/http';
import { HttpClientModule, HttpClient, HttpErrorResponse } from '@angular/common/http';
import { FormsModule } from '@angular/forms';

import { Service } from '../../../server/server';
import { CudTableService } from '../../../public/serve/cud-table/cud-table.service';
import { addDatatype, roledatas } from '../../institution/institution-add-admin/institution-add-admin.component';
import { Pagination } from '../../../public/serve/pcrudInfo';
import { concat } from 'rxjs/operators';
declare var $: any;

@Component({
  selector: 'app-institution-of',
  templateUrl: './institution-of.component.html'
})
export class InstitutionOfComponent implements OnInit {

  constructor(private server: Service, private tableListService: CudTableService) { }

  ngOnInit() {
    this.institutiontreeidnameeventEmit = this.server.institutiontreeidnameeventEmit.subscribe((value: any) => {
      this.superiorofId = value.institutionId;
    })
    //接收机构id
    this.institutionofeventEmit = this.server.institutionofeventEmit.subscribe((value: any) => {
      this.institutionId = value.institutionId;
      this.getTabList(1, 20, this.institutionId, 2);
    })
  }

  //取消订阅
  public institutiontreeidnameeventEmit: any;
  public institutionofeventEmit: any;
  ngOnDestroy() {
    if (this.institutiontreeidnameeventEmit || this.institutionofeventEmit) {
      this.institutiontreeidnameeventEmit.unsubscribe();
      this.institutionofeventEmit.unsubscribe();
    }
  }

  @Input() superiorofId: any;
  public tabVal: any;
  public institutionId: any;

  // 表格
  getTabList(pageNumber, pageSize, id, queryType) {
    let url = this.server.baseUrl + 'admin/pusers/getPusersList';
    let data = new Pagination(pageNumber, pageSize, id, queryType);

    this.tableListService.postRequest(url, data).then((data: any) => {
      this.tabVal = data.result;
      //console.log(this.tabVal);
    }).catch();
  }

}
